package filesearch

import java.text.NumberFormat


/**
 * This service just builds a string with the actual size of
 * the file.
 * 
 * @author mgg
 *
 */
class FileSizeService {
	
    def formatFileSize =  {actualSizeInBytes ->
		def fmt = NumberFormat.getNumberInstance()
		def result
		fmt.setMaximumFractionDigits 2
		double val = actualSizeInBytes / (1024 * 1024)
	 /* in MB */
		if (val > 1){
			return fmt.format(val).concat(" MB")
		}
	/* in KB */
		val = actualSizeInBytes / 1024
		if (val > 10){
			return fmt.format(val).concat(" KB")
		}
	/* just bytes */
		return fmt.format(val).concat(" bytes")
    }
}